package br.com.novagalvao.beans;

import java.math.BigDecimal;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "salario")
public class Salario {

	private int id;
	private BigDecimal valor;
	private int diaPagamento;
	private BigDecimal comissao;

	@Id
	@SequenceGenerator(name = "sequenceGenerator", sequenceName = "salario_seq", allocationSize = 1)
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "sequenceGenerator")
	@Column(name = "id", unique = true, nullable = false)
	public int getId() {
		return id;
	}

	@Column(name = "valor")
	public BigDecimal getValor() {
		return valor;
	}

	@Column(name = "dia_pagamento")
	public int getDiaPagamento() {
		return diaPagamento;
	}

	@Column(name = "comissao", nullable = true)
	public BigDecimal getComissao() {
		return comissao;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setValor(BigDecimal valor) {
		this.valor = valor;
	}

	public void setDiaPagamento(int diaPagamento) {
		this.diaPagamento = diaPagamento;
	}

	public void setComissao(BigDecimal comissao) {
		this.comissao = comissao;
	}

	@Transient
	public Double getCalculaSalarioTototal() {
		if (valor != null) {
			return valor.add(comissao).doubleValue();
		}

		return valor.add(comissao).doubleValue();
	}

}
